package com.yiqi.liebang.feature.wallet.view;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yiqi.liebang.R;
import com.yiqi.liebang.common.widget.dialog.BottomBaseDialog;
import com.yiqi.liebang.common.widget.dialog.BounceBottomEnter;

import butterknife.BindView;

public class RechargeDialog extends BottomBaseDialog<RechargeDialog> {

    private ImageView mBtnClose;

    private  LinearLayout mViewRecharge;

    private  ImageView mBtnBack;

    private ImageView mIvPayAlipay;
    private RelativeLayout mBtnPayAlipay;
    private ImageView mIvPayWechat;
    private RelativeLayout mBtnPayWechat;
    private LinearLayout mViewChooseType;
    private TextView mTvShowPayType;
    private TextView mBtnPay;

    private int mPayType=0;
    private MyClickListenerInterface listenerInterface;
    private TextView mTvShowPrize;

    public RechargeDialog(Context context, View animateView) {
        super(context, animateView);
    }
    private double prize;

    public RechargeDialog(Context context,double prize) {
        super(context);
        this.prize=prize;
    }

    @Override
    public View onCreateView() {
        showAnim(new BounceBottomEnter());
        dismissAnim(null);
        setCanceledOnTouchOutside(false);
        View inflate = View.inflate(mContext, R.layout.dialog_recharge, null);
        mBtnClose = inflate.findViewById(R.id.btn_close);
        mViewRecharge = inflate.findViewById(R.id.view_recharge);
        mViewChooseType = inflate.findViewById(R.id.view_choose_type);
        mBtnBack = inflate.findViewById(R.id.btn_back);
        mTvShowPayType=inflate.findViewById(R.id.tv_show_pay_type);
        mTvShowPrize=inflate.findViewById(R.id.tv_show_prize);
        mBtnPayAlipay=inflate.findViewById(R.id.btn_pay_alipay);
        mBtnPayWechat=inflate.findViewById(R.id.btn_pay_wechat);
        mIvPayAlipay=inflate.findViewById(R.id.iv_pay_alipay);
        mIvPayWechat=inflate.findViewById(R.id.iv_pay_wechat);
        mBtnPay=inflate.findViewById(R.id.btn_recharge_next);
        return inflate;
    }

    @Override
    public void setUiBeforShow() {
        mTvShowPrize.setText("￥"+prize);
        mBtnClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        mTvShowPayType.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mViewRecharge.setVisibility(View.GONE);
                mViewChooseType.setVisibility(View.VISIBLE);
            }
        });
        mBtnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mViewRecharge.setVisibility(View.VISIBLE);
                mViewChooseType.setVisibility(View.GONE);
            }
        });

        mBtnPayAlipay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPayType=0;
                mViewRecharge.setVisibility(View.VISIBLE);
                mViewChooseType.setVisibility(View.GONE);
                mIvPayAlipay.setVisibility(View.VISIBLE);
                mIvPayAlipay.setImageResource(R.drawable.list_button_xuanze);
                mIvPayWechat.setVisibility(View.GONE);
                mTvShowPayType.setText("支付宝");
            }
        });

        mBtnPayWechat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPayType=1;
                mViewRecharge.setVisibility(View.VISIBLE);
                mViewChooseType.setVisibility(View.GONE);
                mIvPayAlipay.setVisibility(View.GONE);
                mIvPayWechat.setImageResource(R.drawable.list_button_xuanze);
                mIvPayWechat.setVisibility(View.VISIBLE);
                mTvShowPayType.setText("微信");
            }
        });

        mBtnPay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listenerInterface.doConfirm(mPayType);
            }
        });
    }

    public void setListener(MyClickListenerInterface listener) {
        this.listenerInterface = listener;
    }


    public interface MyClickListenerInterface {
        void doConfirm(int type);
    }
}